<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ajax登录</title>

    <script src="/static/js/jquery-3.3.1.min.js"></script>
    <script>
        $(function () {
            //绑定按钮的点击事件
            $('#btnLogin').click(function () {
                //获取参数
                username = $('#username').val()
                password = $('#password').val()
                //发起请求
                $.ajax({
                    url:'/login_ajax_check',
                    type:'post',
                    dataType:'json',
                    data:{'username':username,'password':password}
                }).done(function (data) {//语法不一样了，这里调用的是done方法
                    //进行处理
                        {#alert(data.res)#}
                    if(data.res == 0){
                        $('#errmsg').show().html('用户名或密码错误')
                    }else{
                        location.href = ('/index')
                    }
                })
            })
        })
    </script>
    <style>
        #errmsg{
            display: none;
            color:red;
        }
    </style>

</head>
<body>

        用户名：<input type="text" id="username"><br/>
        密码：<input type="password" id="password"><br/>
        <button type="submit" id = 'btnLogin'>登录</button>

<div id = 'errmsg'></div>
</body>
</html>